<template>
    <div class="map-switcher">
        <div v-for="(map, index) in mapTypes" :key="index" class="map-card"
            :class="{ active: currentMapType === map.type }" @click="switchMapType(map.type)">
            <img :src="map.thumbnail" class="thumbnail" />
            <div class="map-title">{{ map.name }}</div>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import {
    DEFAULT_MAP_TYPES,
} from '@/config/mapConfiguration';

import type {
    MapTypeConfig,

} from '@/types/map';


@Component
export default class MapSwitch extends Vue {
    @Prop({ default: () => DEFAULT_MAP_TYPES }) mapTypes!: MapTypeConfig[];
    @Prop() mapInstance;
    private currentMapType: any = 'base';
    private switchMapType(type: string) {
        if (this.currentMapType === type) return;
        const config = this.mapTypes.find(m => m.type === type);
        if (!config) return;
        this.currentMapType = type;
        this.mapInstance.setMapStyle(config.style);
        this.mapInstance.setFeatures(config.features);
    }
}

</script>
<style scoped>
.map-switcher {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.map-card {
    cursor: pointer;
    padding: 8px;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.2s;
}
.map-card:hover {
    transform: translateY(-2px);
}
.map-card.active {
    border-color: #1890ff;
}
.thumbnail {
    width: 50px;
    height: 30px;
    object-fit: cover;
    border-radius: 4px;
}

.map-title {
    font-size: 12px;
    text-align: center;
    margin-top: 4px;
}
</style>